# -*- coding: utf-8 -*-
# author: sixmillions
# date: 2022/04/20
"""
使用工具：https://wxpy.readthedocs.io/zh/latest/
安装：pip3 install wxpy
https://blog.csdn.net/binggan_2019/article/details/88744194
https://blog.csdn.net/for_lazy/article/details/104829432
nohup python3 wx_auto_report.py >> /tmp/wx.log 2>&1 &
"""
from wxpy import *

# 常量
# 群名称，可自定义
GROUP_NAME = 'wxpy测试'
# 成员（成员在群内名称）
all_member = ["张三", "李四", "王五", "陈六"]
# 关键字
KEY_WORD = '接龙'
# 提示数（超过这个值，提示剩下的人）
TIPS_NUM = 2

# 登陆微信
print("--login--")
bot = Bot(cache_path=True)  # True代表本地缓存，不用每次重新扫码
dest_group = bot.groups(update=True).search(GROUP_NAME)[0]
print("群组名称：", dest_group)


@bot.register(dest_group, msg_types=TEXT)
def group(msg):
    print(msg.text)  # 输出群消息
    if msg.text.startswith('#') and KEY_WORD in msg.text:  # 是否包含接龙
        msg_con = msg.text
        finished_num = 0  # 出事接龙人数0
        un_finished_members = ''  # 还没接龙的人员，初始为空
        for member in all_member:
            if member in msg_con:
                finished_num += 1
            else:
                un_finished_members += member + ','
        print('已登记人数：%s人' % finished_num)
        if finished_num == len(all_member):
            print("已经完成接龙，共%s人" % finished_num)
            # 发送微信消息
            msg.sender.send("【统计】今日已经完成接龙，共%s人" % finished_num)
        elif TIPS_NUM < finished_num < len(all_member):  # 申报超过20人，显示未申报人员
            print("当前接龙：%s人。未上报人员：%s。请及时接龙" % (finished_num, un_finished_members))
            # 发送微信消息
            msg.sender.send("【统计】当前接龙：%s人。未上报人员：%s。请及时接龙" % (finished_num, un_finished_members))
    else:
        print("不是接龙消息")
        print(msg.text)


bot.join()  # 开启线程
